﻿using Basic.HrGatewayModular.Interface;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Helper.Config;

namespace Basic.HrGatewayModular.Config
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class LoginVerConfig : ILoginVerConfig
    {
        public LoginVerConfig ( IConfigCollect config )
        {
            IConfigSection section = config.GetSection("Hr:LoginVer");
            section.AddRefreshEvent(this._Init);
        }

        public bool IsOpenVer { get; private set; }
        /// <summary>
        /// 密码输入错误锁定次数
        /// </summary>
        public int LockErrorNum { get; private set; }
        /// <summary>
        /// 验证码错误次数
        /// </summary>
        public int VerCodeErrorNum { get; private set; }
        /// <summary>
        /// 是否进行密码强度验证
        /// </summary>
        public bool PwdStrength { get; private set; }
        /// <summary>
        /// 统计窗口
        /// </summary>
        public int StatisticWindow { get; private set; }

        public int LockTime { get; private set; }

        public string[] LoginFailCode { get; private set; }

        private void _Init ( IConfigSection section, string name )
        {
            this.LoginFailCode = section.GetValue<string[]>("LoginFailCode", new string[] { "hr.emp.not.find", "hr.user.pwd.error" });
            this.IsOpenVer = section.GetValue<bool>("IsOpenVer", true);
            this.LockErrorNum = section.GetValue<int>("LockErrorNum", 3);
            this.VerCodeErrorNum = section.GetValue<int>("VerCodeErrorNum", 1);
            this.StatisticWindow = section.GetValue<int>("StatisticWindow", 60);
            this.LockTime = section.GetValue<int>("LockTime", 120);
            this.PwdStrength = section.GetValue<bool>("PwdStrength", false);
        }
    }
}
